﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;


namespace AnyOffice.general.address.personal
{
    public partial class group_edit : ModulePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int groupId = (Request.QueryString["group_id"] == null) ? 0 : int.Parse(Request.QueryString["group_id"].ToString());
                this.ViewState["GroupId"] = groupId;
                DataTable table = new AddressGroupDao().SelectByGroupId(base.Conn, groupId, base.User.Identity.Name);
                if (table.Rows.Count == 0)
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPrompt("无相关分组！", "group.aspx");
                    return;
                }
                this.txtGroupName.Text = table.Rows[0]["GroupName"].ToString();
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                AddressGroupDao dao2 = new AddressGroupDao();
                AddressGroupData data = new AddressGroupData();
                data.GroupId = Convert.ToInt32(this.ViewState["GroupId"].ToString());
                data.GroupName = this.txtGroupName.Text;
                data.UserId = base.User.Identity.Name;
                dao2.Update(base.Conn, data);
                this.litMessage.Text = base.ShowPrompt("分组编辑成功！", "group.aspx");
                StringBuilder builder = new StringBuilder("<script>\n");
                builder.Append("parent.menu.location.reload();\n");
                builder.Append("parent.main.location='group.aspx';\n");
                builder.Append("</script>\n");
                if (!this.Page.IsClientScriptBlockRegistered("AddressGroup_list"))
                {
                    this.Page.RegisterClientScriptBlock("AddressGroup_list", builder.ToString());
                }
            }
        } 

    }
}
